<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CC的办公系统</title>
<!--#include file="lib/plugins.asp"-->
<style type="text/css">
  .ui-datepicker table {
    border: 0;
  }
  .yform label{
    display:inline;
  }
</style>
<script type="text/javascript">
  $(function() {
    $("#form1").validationEngine();
    function Calc_Goods_Price(){
      $("#goods_price").val((tonumber($("#goods_quantity").val())*tonumber($("#goods_unitprice").val())).toFixed(2));
    }
    $("#goods_quantity,#goods_unitprice").change(function(){
      Calc_Goods_Price();
    });
  });
</script>
<!--#include file="lib/js-google-analytics.asp"-->
</head>
<%
if not CheckPostFlag(session("aaPostFlag"),3,5) then call JumpErrorPage(2)
goods_id=saferequest("goods_id",1)
submit=saferequest("submit",0)
If submit<>"" Then
  conn.BeginTrans
  goods_class=saferequest("goods_class",1)
  goods_name=saferequest("goods_name",0)
  goods_brand=saferequest("goods_brand",1)
  goods_model=saferequest("goods_model",0)
  goods_spec=saferequest("goods_spec",0)
  goods_unit=saferequest("goods_unit",1)
  goods_quantity=cdbl(saferequest("goods_quantity",1))
  goods_quantity_old=cdbl(saferequest("goods_quantity_old",1))
  goods_unitprice=cdbl(saferequest("goods_unitprice",1))
  goods_stock=cdbl(saferequest("goods_stock",1))
  goods_price=goods_quantity*goods_unitprice
  goods_memo=saferequest("goods_memo",0)
  goods_returns=goods_quantity_old-goods_quantity
  
  if goods_returns<=goods_stock then 
    if submit="保存" then
      sql="update goods set goods_class="&goods_class&",goods_name='"&goods_name&"',goods_brand="&goods_brand&",goods_model='"&goods_model&"',goods_spec='"&goods_spec&"',goods_unit="&goods_unit&",goods_quantity="&goods_quantity&",goods_unitprice="&goods_unitprice&",goods_price="&goods_price&",goods_memo='"&goods_memo&"' where goods_id="&goods_id
      ' response.write sql
      ' response.end
      call ExecuteCommand(sql,false)
    end if
  else
    response.write("进货数量少于领用量，修改失败")
    response.end
  end if
  if err.number=0 then 
    conn.CommitTrans  '如果没有conn错误，则执行事务提交
  else
    conn.RollbackTrans '否则回滚
    '回滚后的其他操作
    'strerr=err.Description
    url=request.ServerVariables("http_host")&request.ServerVariables("url")
    Response.Write "数据库错误！<br /><font color=red>Error # " & CStr(Err.Number) & "<br />" & Err.Description & "<br />Source: " & Err.Source &"<br />错误页面："&url&"</font><br />"
    Response.End
  end if
end if
%>
<body>
<!--#include file="lib/header.asp"-->
<!--#include file="lib/nav.asp"-->
<div id="main">
<!--#include file="lib/col1.asp"-->
<!--#include file="lib/col2.asp"-->
  <div id="col3" role="main">
    <div id="col3_content" class="clearfix">
      <div>
        <%
          set rs = Server.CreateObject("ADODB.Recordset")
          sql="select * from goods_stock where goods_id="&goods_id
          rs.open sql,conn,1,1
          if not rs.eof then
        %>
        <form id="form1" name="form1" method="post" class="yform" role="application">
          <div>
            <table class="full">
              <tbody>
                <tr>
                  <td>序号</td><td><%=rs("goods_id")%></td>
                  <td>批次</td><td><%=rs("goods_purchase")%></td>
                </tr>
                <tr>
                  <td>分类</td>
                  <td>
                    <select id="goods_class" name="goods_class">
                    <%
                      Set rs_class = Server.CreateObject("ADODB.Recordset")
                      sql_class = "SELECT * FROM class order by class_name"
                      rs_class.Open sql_class,conn,1,1
                      do while not rs_class.eof
                    %>
                      <option value="<%=rs_class("class_id")%>" <%if rs_class("class_id")=rs("goods_class") then response.write("selected='selected'")%>><%=rs_class("class_name")%></option>
                    <%
                        rs_class.movenext
                      loop
                      rs_class.close
                      set rs_class=nothing
                    %>
                    </select>
                  </td>
                  <td>文具名</td><td><input type="text" class="validate[required]" name="goods_name" id="goods_name" value="<%=rs("goods_name")%>" /></td>
                </tr>
                <tr>
                  <td>品牌</td>
                  <td>
                    <select id="goods_brand" name="goods_brand">
                    <%
                      Set rs_brand = Server.CreateObject("ADODB.Recordset")
                      sql_brand = "SELECT * FROM brand order by brand_name"
                      rs_brand.Open sql_brand,conn,1,1
                      do while not rs_brand.eof
                    %>
                      <option value="<%=rs_brand("brand_id")%>" <%if rs_brand("brand_id")=rs("goods_brand") then response.write("selected='selected'")%>><%=rs_brand("brand_name")%></option>
                    <%
                        rs_brand.movenext
                      loop
                      rs_brand.close
                      set rs_brand=nothing
                    %>
                    </select>
                  </td>
                  <td>型号</td><td><input type="text" name="goods_model" id="goods_model" value="<%=rs("goods_model")%>" /></td>
                </tr>
                <tr>
                  <td>规格</td><td><input type="text" name="goods_spec" id="goods_spec" value="<%=rs("goods_spec")%>" /></td>
                  <td>单位</td>
                  <td>
                    <select id="goods_unit" name="goods_unit">
                    <%
                      Set rs_unit = Server.CreateObject("ADODB.Recordset")
                      sql_unit = "SELECT * FROM unit order by unit_name"
                      rs_unit.Open sql_unit,conn,1,1
                      do while not rs_unit.eof
                    %>
                      <option value="<%=rs_unit("unit_id")%>" <%if rs_unit("unit_id")=rs("goods_unit") then response.write("selected='selected'")%>><%=rs_unit("unit_name")%></option>
                    <%
                        rs_unit.movenext
                      loop
                      rs_unit.close
                      set rs_unit=nothing
                    %>
                    </select>
                  </td>
                </tr>
                <tr>
                  <td>进货数量</td><td><input type="text" name="goods_quantity" id="goods_quantity" value="<%=rs("goods_quantity")%>" class="validate[custom[onlyNumber],min[<%=cdbl(rs("goods_quantity")-rs("goods_stock"))%>]]" /><input type="hidden" name="goods_quantity_old" id="goods_quantity_old" value="<%=rs("goods_quantity")%>" /></td>
                  <td>库存数量</td><td><input type="text" name="goods_stock" id="goods_stock" value="<%=rs("goods_stock")%>" readonly="readonly" /></td>
                </tr>
                <tr>
                  <td>单价</td><td><input type="text" name="goods_unitprice" id="goods_unitprice" value="<%=rs("goods_unitprice")%>" class="validate[required,custom[number]]" /></td>
                  <td>金额</td><td><input type="text" name="goods_price" id="goods_price" value="<%=rs("goods_price")%>" readonly="readonly" /></td>
                </tr>
                <tr>
                  <td>备注</td><td><input type="text" name="goods_memo" id="goods_memo" value="<%=rs("goods_memo")%>" /></td>
                  <td></td><td></td>
                </tr>
              </tbody>
            </table>
          </div>
          <input type="submit" name="submit" value="保存" />
          <input name="reset" type="reset" value="重置" />
        </form> 
        
        <%
          end if
          rs.close
          set rs=nothing
        %>
      </div>
      <div>
      该文具领用记录
        <table class="full">
          <thead>
            <tr>
              <th scope="col">序号</th>
              <th scope="col">领用日期</th>
              <th scope="col">员工</th>
              <th scope="col">部门</th>
              <th scope="col">批号</th>
              <th scope="col">分类</th>
              <th scope="col">文具名</th>
              <th scope="col">品牌</th>
              <th scope="col">型号</th>
              <th scope="col">规格</th>
              <th scope="col">单位</th>
              <th scope="col">数量</th>
              <th scope="col">单价</th>
              <th scope="col">金额</th>
              <th scope="col">经手人</th>
              <th scope="col">结算</th>
              <th scope="col">备注</th>
            </tr>
          </thead>
          <tbody>
        <%
          set rs = Server.CreateObject("ADODB.Recordset")
          sql="select * from offer_goods where goods_id="&goods_id&" order by offer_update desc"
          rs.open sql,conn,1,1
          do while not rs.eof
        %>
            <tr>
              <th class="sub" scope="row"><%=rs.AbsolutePosition%></th>
              <td><%=rs("offer_date")%></td>
              <td><%=rs("empe_name")%></td>
              <td><%=rs("dept_name")%></td>
              <td><%=rs("goods_purchase")%></td>
              <td><%=rs("class_name")%></td>
              <td title="<%=rs("goods_memo")%>"><%=rs("goods_name")%></td>
              <td><%=rs("brand_name")%></td>
              <td><%=rs("goods_model")%></td>
              <td><%=rs("goods_spec")%></td>
              <td><%=rs("unit_name")%></td>
              <td><%=rs("offer_quantity")%></td>
              <td><%=rs("goods_unitprice")%></td>
              <td><%=rs("offer_price")%></td>
              <td><%=rs("fullname")%></td>
              <td><%if rs("offer_bill") then response.write "是"%></td>
              <td><%=rs("offer_memo")%></td>
            </tr>
        <%
          rs.movenext()
        loop
        %>
          </tbody>
        </table>      
      </div>

    </div>
  </div>
</div>
<!--#include file="lib/footer.asp"-->
</body>
</html>
<!--#include file="lib/connclose.asp"-->

